package org.jmetrix.samples.application;

import org.jmetrix.monitor.impl.SimpleMonitor;

/**
 * @author Konstantin Kuzmin
 * @version $Revision$
 * @since 14.10.12
 */
public class ThroughputSample {
    public static final OrderManager orderManager = new OrderManager();
    private static final long MAX_MILLIS_TO_SEND_INVOICE = 100;

    public static void main(String[] args) throws Exception {
        // Create and start performance monitor
        SimpleMonitor simpleMonitor = new SimpleMonitor();
        simpleMonitor.start();

        try {
            // Do some sendInvoice calls
            for (int i = 0; i <= 100; i++) {
                orderManager.sendInvoice((long) (Math.random() * MAX_MILLIS_TO_SEND_INVOICE));
            }
            // Output performance metrics
            System.out.println("Performance metrics: " + simpleMonitor.getMetrixAggregator());
        } finally {
            // Stop the performance monitor (not necessary)
            simpleMonitor.stop();
        }

    }
}
